/**
 * 医疗服务质询初始化模块，提供医疗服务编辑页面初始化组件功能
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","valueUtil","commonSelect","inpatient","medicalInfo"],
		function($,sysmanMain,valueUtil,commonSelect,inpatient,medicalInfo) {
			
		'use strict';
		
		var public_method ={
			
			bizInit:function(_options){
				if(_options){
					if(_options.rootId){
						var _startDate = $('#' + _options.rootId + ' #outhospitalat_start')
						
						var _endDate = $('#' + _options.rootId + ' #outhospitalat_end')
						if(_startDate.length>0){
							var curDate = new Date();
							
							var _tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
							$(_endDate).datebox('setValue',_tmp);							
							
							
							curDate.setDate(1);
							
							_tmp = valueUtil.getDateValue({source:curDate,format:'yyyy-MM-dd'})
							$(_startDate).datebox('setValue',_tmp);
						}
					}

					
				}
			},			
			
			/**
			 * 设置模块点击页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickCell:function(index,field,value){
				
				var _config = sysmanMain.getCurrentModuConfig()
				
				if(!value  || value<=0){
					_config.clickValue = 0
					sysmanMain.setCurrentModuConfig(_config)
					return 
				}else{
					_config.clickValue = 1
					sysmanMain.setCurrentModuConfig(_config)
				}
				var _param ={}
				if(field && (field!=='sumary_matter')){
					_param.issue = field					
				}				
				
				_config.clickParam = _param				
				sysmanMain.setCurrentModuConfig(_config)
				
			},
			
			/**
			 * 设置模块点击参数页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickRow:function(index,row){
				if(window.console){
					console.log('index:' + index)
					console.log('row.doct_depart_name:' + row.doct_depart_name)					
				}
				var _config = sysmanMain.getCurrentModuConfig()	
				
				//点击为0cell
				if(_config.clickValue <= 0){
					return 
				}
				var _param = {doct_depart_code:row.doct_depart_code}
				if (_config.clickParam){					
					$.extend(_config.clickParam,_param) 
				}else{
					_config.clickParam = _param
				}
				sysmanMain.setCurrentModuConfig(_config)
				
				var initQueryParams = {condition:_config.clickParam}
				
				
				sysmanMain.setModuConf('medicalInfo',{initQueryParams:initQueryParams})
				
				sysmanMain.medicalInfoSelect()
			},
			/**
			 * 设置模块点击页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickBizStaticCell:function(index,field,value){
				
				var _config = sysmanMain.getCurrentModuConfig()
				
				if(!value  || value<=0){
					_config.clickValue = 0
					sysmanMain.setCurrentModuConfig(_config)
					return 
				}else{
					_config.clickValue = 1
					sysmanMain.setCurrentModuConfig(_config)
				}
				var _param ={}
				
				_param.issue = field					
								
				
				_config.clickParam = _param				
				sysmanMain.setCurrentModuConfig(_config)
				
			},
			
			/**
			 * 设置模块点击参数页面
			 * @param _options.record 列表选中行
			 * @param _options.grid 页面form对象
			 * @param _options.rootId 页面根节点
			 */
			clickBizStaticRow:function(index,row){
				if(window.console){
					console.log('index:' + index)
					console.log('row.doct_depart_name:' + row.doct_depart_name)					
				}
				var _config = sysmanMain.getCurrentModuConfig()	
				
				//点击为0cell
				if(_config.clickValue <= 0){
					return 
				}
				
				var _issue 
				var _param = {doct_depart_code:row.doct_depart_code}
				if (_config.clickParam && _config.clickParam.issue){
					_issue = _config.clickParam.issue
					var _startValue = $('#panel-medical-biz-statistic #outhospitalat_start').datebox('getValue')
					
					var _endValue = $('#panel-medical-biz-statistic #outhospitalat_end').datebox('getValue')
					
					
					
					var queryRecipel = false;
					switch(_config.clickParam.issue){
						case 'inpatient_num':
							_param.inhzospitalat_end=_endValue
							_param.outhospitalat_ge_or_null= _startValue
							break;
						case 'inpatient_month_admission':
							_param.inhzospitalat_end=_endValue
							_param.inhzospitalat_start=_startValue
							break;
						case 'inpatient_month_out':
							_param.outhospitalat_end=_endValue
							_param.outhospitalat_start=_startValue
							break;
						case 'sumary_matter':
							_param.outhospitalat_start=_startValue
							_param.outhospitalat_end=_endValue
							break;
						case 'large_cost':
							_param.issue = 'fee_wrong';
							_param.inquiry_item_code = 5
							_param.inquiry_item_subcode = 185
							_param.inhzospitalat_start_less=_startValue
							_param.inhzospitalat_end=_endValue
							_param.outhospitalat_end_null=_endValue							
							queryRecipel = true;
							break;
						case 'treat_wrong':
							_param.issue = '';
							_param.inquiry_item_code = 177
							_param.inquiry_item_subcode = 182
							_param.outhospitalat_start=_startValue
							_param.outhospitalat_end=_endValue
							queryRecipel = true;
							break;
						case 'bed_wrong':
							_param.issue = '';
							_param.inquiry_item_code = 177
							_param.inquiry_item_subcode = 181
							_param.outhospitalat_start=_startValue
							_param.outhospitalat_end=_endValue
							queryRecipel = true;
							break;
						case 'nursing_wrong':
							_param.issue = '';
							_param.inquiry_item_code = 177
							_param.inquiry_item_subcode = 178
							_param.outhospitalat_start=_startValue
							_param.outhospitalat_end=_endValue
							queryRecipel = true;
							break;
					}
					$.extend(_config.clickParam,_param) 
				}else{
					_config.clickParam = _param
				}
				sysmanMain.setCurrentModuConfig(_config)				
				
				
				if(!queryRecipel){
					//查询出院表
					if(_issue && (_issue!='sumary_matter')){
										
					
						sysmanMain.setModuConf('medicalBizInfo',{initQueryParams:{condition:_config.clickParam}})
						var _rootPath = sysmanMain.getRootPath();
						commonSelect.medicalBizInfoSelect({rootPath:_rootPath})
					}
				}else{
					//查询质询表
					medicalInfo.pageOpen({
						queryModule: 'medicalRecipel',
						queryMethod: 'getBetweenListDomain',
						initQueryParams : {condition:_config.clickParam}
					})
					
				}
			},
			clickBizRow:function(index,data){
				
				inpatient.rowClick(index,data)
			}
		}			
		
		return public_method;
			
})